<?php

namespace App\Http\Controllers\NB\SWC;
use DB;
use Illuminate\Http\Request;
use App\Http\Controllers\common\PublicController;

class Cover_checkController extends PublicController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        return view('NB.SWC.coverCheck.index');
    }

    //获取代理商下所有区域
    public function postArea(Request $request){
        //获取代理商id
        $agent_id = $request -> cookie('logon')['agent_id'];
        if($this -> area_ids === '0'){
            $areaInfo = DB::table('area') -> where('agent_id',$agent_id) -> get();
        }else{
            $areaInfo = DB::table('area') -> whereIn("area.id",explode(",",$this -> area_ids)) -> where('agent_id',$agent_id) -> get();
        }
        return json_encode($areaInfo);
    }

    //获取代理商下所有建筑
    public function postBuilding(Request $request){
        //获取区域id
        $area_id = $request -> input('area_id');
        //获取代理商id
        $agent_id = $request -> cookie('logon')['agent_id'];
        $areaInfo = DB::table('building') -> where('area_id',$area_id) -> where('agent_id',$agent_id) -> get();
        return json_encode($areaInfo);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
